/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is property of Nordic Semiconductor ASA.
 * Terms and conditions of usage are described in detail in NORDIC
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 *
 * Licensees are granted free, non-transferable use of the information. NO
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 * the file.
 *
 */

/**@file
 *
 * @defgroup nrf_bootloader_types Types and definitions.
 * @{
 *
 * @ingroup nrf_bootloader
 *
 * @brief Bootloader module type and definitions.
 */

#ifndef BOOTLOADER_TYPES_H__
#define BOOTLOADER_TYPES_H__
#include "ble_gap.h"
#include <stdint.h>

#define BOOTLOADER_DFU_DATA_IN_EXT_FLASH (0x98)
#define BOOTLOADER_DFU_IN_APPL (0xB1)
#define BOOTLOADER_DFU_SINGLE_FLAG (0xBB)
#define BOOTLOADER_SVC_APP_DATA_PTR_GET 0x02

#define BOOTLOADER_SETTINGS_ADDRESS 0x0007F000

/**@brief DFU Bank state code, which indicates wether the bank contains: A valid image, invalid image, or an erased flash.
 */
typedef enum
{
    BANK_VALID_APP = 0x01,
    BANK_VALID_SD = 0xA5,
    BANK_VALID_BOOT = 0xAA,
    BANK_ERASED = 0xFE,
    BANK_INVALID_APP = 0xFF,
} bootloader_bank_code_t;

/**@brief Structure holding bootloader settings for application and bank data.
 */
typedef struct
{
    uint32_t code_size;
    uint16_t crc16;
    uint16_t checksum;
    uint8_t product_sn[16];
    uint8_t device_name[32];
    uint8_t device_hw[32];
    uint8_t device_fw[32];
    ble_gap_id_key_t id_key;
    ble_gap_enc_key_t enc_key;

    uint8_t boot_button_num;   //按键IO
    uint8_t boot_button_pull;  //上下拉
    uint8_t boot_button_sense; //检测电平
    uint32_t flash_enc_key;    // flash内容加密秘钥

    uint32_t ext_flash_start_address; //片外flash的起始地址
    uint8_t ext_flash_pin_cs;
    uint8_t ext_flash_pin_clk;
    uint8_t ext_flash_pin_mosi;
    uint8_t ext_flash_pin_miso;
} bootloader_settings_t;

extern bootloader_settings_t boot_settings; //变量在m_ota内定义了
void bootloader_settings_info_save(void);
#endif // BOOTLOADER_TYPES_H__

/**@} */
